/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ADT;


/**
 *
 * @author Martin
 */
/**
 *
 * @author Martin
 */
public class WorkInJ extends Scalar implements Work{
    private final double joule;
    
    @Override public boolean isZero(){ return joule==0.0; }
    @Override public boolean isValid(){ return true; }
    
    public WorkInJ(double  joule){
        this.joule =  joule;
    } 
    
    @Override
    public Work inverse(){
        return new WorkInJ(this.joule * -1);
    }
    
    @Override
    public double  getJ(){
        return joule;
    }
       
    @Override
    public Work add(Work work){
       return valueOf(this.getJ() + work.getJ());
    }
   
    @Override
    public Work sub(Work work){
        return valueOf(this.getJ() - work.getJ());
    }
    
    @Override
    public Work div(double factor){
        return valueOf(this.joule / factor);
    }
    
    @Override
    public  Work mul(double factor){
        return valueOf(this.joule * factor);
    }
    
    @Override
    public double div(Work work){
        return this.joule / work.getJ();
    }
    
    
    public String toString(Work work){
        return String.format("%.2d Joule");
    }
    
    @Override
    public int compareTo(Work work){
        return Double.compare(this.joule, work.getJ());
    }
    
    @Override
    public boolean equals(Object o){
        if(this == o) return true;
        if(!(o instanceof WorkInJ)) return false;
        return this.compareTo((WorkInJ)o) == 0;
    }
    
    
    public static Work valueOf(double joule){
        return new WorkInJ(joule);
    }
    
    @Override
    public int hashCode(){
        return hashDouble(joule);
    }
}